/*--------------------------------------------------------------------------
  Project::MONDIALI SCI ALPINISMO
  Package::States
  Class::NewScenarioState
  File NewScenarioState.h
  --------------------------------------------------------------------------
  * METHODS AND CLASS PARAMETERS


  --------------------------------------------------------------------------
  * FUNCTIONS DESCRIPTION
  
	...

  --------------------------------------------------------------------------
  * COPYRIGHT

  --------------------------------------------------------------------------
  * INFO ABOUT AUTHOR AND VERSIONS
  Author:	Tino Giorgio	Data: 
  Rev1:			Data:

  --------------------------------------------------------------------------
  * E-MAIL & CONTACTS

  GIORGIO TINO:	tinoshi@libero.it
	           	shapeofangels@hotmail.com
	            giorgio.tino@studenti.polito.it

  --------------------------------------------------------------------------*/

#if !defined(NEWSCENARIOSTATE_H)
#define NEWSCENARIOSTATE_H

#include <stdio.h>
#include <stdlib.h>

#include <plib/pu.h>
#include <plib/puAux.h>
#include <plib/fnt.h>

/* Application Includes*/
#include "State.h"
#include "LoadingInfo.h"

/* DEFINES */
#define NEW_SCENARIO_SELECTION 0
#define NEW_SCENARIO_LOADING   1
#define NEW_SCENARIO_CANCELING 2
#define NEW_SCENARIO_SELECTED  3

#define MAX_TEXT_LENGHT 1024

#define COLOR_SUNBURST 1.0f,0.7f,0.0f,1.0f
#define COLOR_RED      1.0f,0.0f,0.0f,1.0f
#define COLOR_BLACK    0.0f,0.0f,0.0f,1.0f
#define COLOR_ICE      0.0f,0.2f,0.6f,0.4f
#define COLOR_BLUE     0.0f,0.0f,1.0f,1.0f
#define COLOR_WHITE    1.0f,1.0f,1.0f,1.0f

#define INFO_STRING "Choose a .DEM file: others file will be searched by default using standard names.\nIf you want you can change those names manually.\n"

class ScenarioCreationState;
class BackGroundImage;
class ImageButton;
class VideoImage;
class ProgressBar;
class Keyboard;
class Mouse;
class Joystick;

class NewScenarioState : public State
{
public:
	NewScenarioState();
	NewScenarioState(State* oldState);
	virtual ~NewScenarioState();
	
	//
	// Static memebr functions (callbacks for PUI menu)
	//
	static unsigned int loadNewScenario(void *);
	static void pick_dem ( puObject * );
	static void pick_tex ( puObject * );
	static void pick_map ( puObject * );
	static void pick_obj ( puObject * );
	static void browse_dem ( puObject * );
	static void browse_tex ( puObject * );
	static void browse_map ( puObject * );
	static void browse_obj ( puObject * );
	
	//
	// class 'callbacks' (they aren't callbacks really...)
	//
	void load(const char* filename);
    void display(void);
    void resize(int w, int h);
    void keyUp(unsigned char key, int x, int y);
    void keyDown(unsigned char key, int x, int y);
    void specialUp(int key, int x, int y);
    void specialDown(int key, int x, int y);
    void motion(int newx, int newy); 
    void passive(int newx, int newy);
    void mouse(int button, int state, int mouseX, int mouseY);
    State* idle(void);
    void reset();
	void reload();
	void reopen();

	char dem_file[MAX_TEXT_LENGHT];
	char map_file[MAX_TEXT_LENGHT];
	char tex_file[MAX_TEXT_LENGHT];
	char obj_file[MAX_TEXT_LENGHT];
	char wpn_file[MAX_TEXT_LENGHT];
	char cmv_file[MAX_TEXT_LENGHT];

    int innerState; // current sub state

private:
    BackGroundImage *backgroundImage;
    ImageButton *backButton,*backDisabledButton,*cancelButton,*cancelDisabledButton,*loadButton;
    VideoImage *loadingImage,*cancelingImage;
    ProgressBar *scenarioProgressBar,*mapProgressBar,*textureProgressBar;
    
    bool cancelButtonEnabled;
    bool backButtonEnabled;
    
    Keyboard *kb;
    Mouse *ms;
    
	void createPUI(int w, int h);
	void loadTextures(LoadingInfo *li);
	void deleteNextState();
	void readAndLoadLandTextures(LoadingInfo *li);
	void readAndLoadObjectsTextures(LoadingInfo *li);
    
    State* nextState;
    State* oldState;
    
	bool shouldDeleteNextState;

    LoadingInfo info;
    
    float progress;

	bool lc;

	// Fonts
	puFont     *font, *tex_font ;
    fntTexFont *fnt  ;

	// PUI group
	puGroup *progress_group;
	puGroup *file_group;
	puGroup *browse_group;
    
	// Text widgets
	puText		*scenario_progress_text;
	char		scenario_progress_label[MAX_TEXT_LENGHT];

	puText		*map_progress_text;
	char		map_progress_label[MAX_TEXT_LENGHT];

	puText		*texture_progress_text;
	char		texture_progress_label[MAX_TEXT_LENGHT];

	puText		*info_text;
	char		info_label[MAX_TEXT_LENGHT];

	puaFileSelector *demFileSelector; 
	puaFileSelector *mapFileSelector; 
	puaFileSelector *texFileSelector; 
	puaFileSelector *objFileSelector; 

	puFrame      *demFileText;        
	puFrame      *mapFileText;        
	puFrame      *texFileText;        
	puFrame      *objFileText;        

	puOneShot   *demFileBrowse;
	puOneShot   *mapFileBrowse;
	puOneShot   *texFileBrowse;
	puOneShot   *objFileBrowse;
};

#endif // !defined(NEWSCENARIOSTATE_H_)
